package com.saver.view.dialog;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.saver.R;
import com.saver.core.domain.Categoria;
import com.saver.view.TransactionListActivity;
import com.saver.view.gui.CircleView;

/**
 * Created by HeRGoS on 18/04/2015
 */
public class CategoriaSpinerAdapter extends ArrayAdapter<Categoria> {

    public CategoriaSpinerAdapter(Context context, int textViewResourceId, Categoria[] objects) {
        super(context, textViewResourceId, objects);
    }

    @Override
    public View getDropDownView(int position, View convertView, ViewGroup parent) {
        return getCustomView(position, convertView, parent);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        return getCustomView(position, convertView, parent);
    }

    public View getCustomView(int position, View convertView, ViewGroup parent) {
        View view = convertView == null ? LayoutInflater.from(getContext()).inflate(R.layout.item_categoria, parent, false) : convertView;
        TextView nombreCategoria = (TextView) view.findViewById(R.id.nombre_categoria);
        Categoria categoria = getItem(position);
        nombreCategoria.setText(categoria.getNombre().trim().toUpperCase());
        String[] rgb = categoria.getColor().split(",");
        int color = Color.rgb(Integer.parseInt(rgb[0]), Integer.parseInt(rgb[1]), Integer.parseInt(rgb[2]));
        CircleView icono = (CircleView) view.findViewById(R.id.icon_category);
        icono.setTitleText(categoria.getNombre().trim().substring(0, 1).toUpperCase());
        icono.setStrokeColor(color);
        icono.setTitleColor(color);
        icono.setFillColor(color & 0x60FFFFFF);
        view.setBackgroundColor(color & 0x60FFFFFF);
        nombreCategoria.setTextColor(color);

        return view;
    }
}